package com.easy.user.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.common.bean.SysPermission;
import com.easy.common.service.IPermissionService;
import com.easy.user.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissonService extends ServiceImpl<PermissionMapper,SysPermission> implements IPermissionService {

    @Autowired
    PermissionMapper sysPermissionMapper;

    @Override
    public SysPermission insert(SysPermission sysPermission) {
        // 插入权限记录
        sysPermissionMapper.insert(sysPermission);
        // 返回插入后的权限记录
        return sysPermissionMapper.selectById(sysPermission.getId());
    }

    @Override
    public SysPermission update(SysPermission sysPermission) {
        // 更新权限记录
        sysPermissionMapper.updateById(sysPermission);
        // 返回更新后的权限记录
        return sysPermissionMapper.selectById(sysPermission.getId());
    }

    @Override
    public int delete(Integer id) {
        // 删除指定 ID 的权限记录，并返回受影响的行数
        return sysPermissionMapper.deleteById(id);
    }

    @Override
    public SysPermission getById(Integer id) {
        // 根据 ID 查询权限记录
        return sysPermissionMapper.selectById(id);
    }

    @Override
    public IPage<SysPermission> getListByPage(IPage page, SysPermission sysPermission) {
        // 创建查询条件包装器
        QueryWrapper<SysPermission> queryWrapper = new QueryWrapper<>(sysPermission);
        // 分页查询权限记录
        return sysPermissionMapper.selectPage(page, queryWrapper);
    }

    @Override
    public List<SysPermission> getList(SysPermission sysPermission) {
        // 创建查询条件包装器
        QueryWrapper<SysPermission> queryWrapper = new QueryWrapper<>(sysPermission);
        // 查询权限记录列表
        return sysPermissionMapper.selectList(queryWrapper);
    }
}